package com.camel.docker.controller;

import com.camel.docker.entity.Result;
import com.camel.docker.enums.ResultEnum;
import com.camel.docker.utils.DockerClientExceptionUtils;
import com.camel.docker.utils.ResultUtil;
import com.github.dockerjava.api.exception.ConflictException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

@ControllerAdvice
@RestController
public class ExceptionHandlerController {
    @ExceptionHandler(value = ConflictException.class)
    public Result conflictExceptionHandler(ConflictException e) {
        String msg = e.getMessage();
        Result result = DockerClientExceptionUtils.trans(msg, null);
        return ResultUtil.error(ResultEnum.NOT_VALID_PARAM, result.getMsg());
    }
}
